package com.joker.web.controller.orange;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.joker.common.annotation.RepeatSubmit;
import com.joker.common.annotation.Log;
import com.joker.common.core.controller.BaseController;
import com.joker.common.core.domain.PageQuery;
import com.joker.common.core.domain.R;
import com.joker.common.core.validate.AddGroup;
import com.joker.common.core.validate.EditGroup;
import com.joker.common.enums.BusinessType;
import com.joker.common.utils.poi.ExcelUtil;
import com.joker.orange.domain.vo.CaricatureCategoryVo;
import com.joker.orange.domain.bo.CaricatureCategoryBo;
import com.joker.orange.service.ICaricatureCategoryService;
import com.joker.common.core.page.TableDataInfo;

/**
 * 漫画分类
 *
 * @author Joker
 * @date 2024-06-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/pixiv/caricatureCategory")
public class CaricatureCategoryController extends BaseController {

    private final ICaricatureCategoryService iCaricatureCategoryService;

    /**
     * 查询漫画分类列表
     */
    @SaCheckPermission("pixiv:caricatureCategory:list")
    @GetMapping("/list")
    public TableDataInfo<CaricatureCategoryVo> list(CaricatureCategoryBo bo, PageQuery pageQuery) {
        return iCaricatureCategoryService.queryPageList(bo, pageQuery);
    }

    @SaCheckPermission("pixiv:caricatureCategory:list")
    @GetMapping("/queryList")
    public R<List<CaricatureCategoryVo>> queryList() {
        return R.ok(iCaricatureCategoryService.queryList(new CaricatureCategoryBo()));
    }

    /**
     * 导出漫画分类列表
     */
    @SaCheckPermission("pixiv:caricatureCategory:export")
    @Log(title = "漫画分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CaricatureCategoryBo bo, HttpServletResponse response) {
        List<CaricatureCategoryVo> list = iCaricatureCategoryService.queryList(bo);
        ExcelUtil.exportExcel(list, "漫画分类", CaricatureCategoryVo.class, response);
    }

    /**
     * 获取漫画分类详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("pixiv:caricatureCategory:query")
    @GetMapping("/{id}")
    public R<CaricatureCategoryVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iCaricatureCategoryService.queryById(id));
    }

    /**
     * 新增漫画分类
     */
    @SaCheckPermission("pixiv:caricatureCategory:add")
    @Log(title = "漫画分类", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CaricatureCategoryBo bo) {
        return toAjax(iCaricatureCategoryService.insertByBo(bo));
    }

    /**
     * 修改漫画分类
     */
    @SaCheckPermission("pixiv:caricatureCategory:edit")
    @Log(title = "漫画分类", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CaricatureCategoryBo bo) {
        return toAjax(iCaricatureCategoryService.updateByBo(bo));
    }

    /**
     * 删除漫画分类
     *
     * @param ids 主键串
     */
    @SaCheckPermission("pixiv:caricatureCategory:remove")
    @Log(title = "漫画分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iCaricatureCategoryService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
